package com.yyk.yiliao.ui.message;

import android.os.Handler;


import com.hyphenate.chat.EMClient;
import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.easeui.domain.EaseUser;
import com.hyphenate.easeui.ui.EaseChatFragment;
import com.hyphenate.easeui.utils.EaseUserUtils;
import com.hyphenate.exceptions.HyphenateException;
import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;


/**
 * 环信sdk实现登录注册功能（第三方通信） - 郑清的IT学习之路 - CSDN博客  https://blog.csdn.net/qq_38225558/article/details/80501209
 * <p>
 * EaseUserUtils 这块有问题，提示glide异常
 */
public class SendAMessageActivity extends BaseActivity {

    private Handler handler = new Handler();

    private EaseChatFragment chatFragment;
    private String doctorname;


    @Override
    public int getLayoutId() {
        return R.layout.activity_send_amessage;
    }

    @Override
    public void initView() {
        initToolbar();
        try {
            EMClient.getInstance().contactManager().acceptInvitation(getIntent().getStringExtra(EaseConstant.EXTRA_USER_ID));
        } catch (HyphenateException e) {
            e.printStackTrace();
        }

    }

    private void initToolbar() {
        setBackArrow();
        //从环信用户查找 昵称
        String toChatUsername = getIntent().getStringExtra(EaseConstant.EXTRA_USER_ID);
        EaseUser userInfo = EaseUserUtils.getUserInfo(toChatUsername);
        if (userInfo != null) {
            setTitle(userInfo.getNickname());
        } else {
            if (doctorname != null) {
                setTitle(doctorname);
            } else {
                setTitle("聊天");
            }
        }

//        hidetoolBar();
//        chatFragment.hideTitleBar();
    }

    public void initData() {
        initIntent();
        // 这里直接使用EaseUI封装好的聊天界面
        //new出EaseChatFragment或其子类的实例
        chatFragment = new ChatFragment();
        //传入参数
//        String guokun = getIntent().getStringExtra(EaseConstant.EXTRA_USER_ID);
//        String chat = getIntent().getStringExtra(EaseConstant.EXTRA_CHAT_TYPE);
//        Bundle args = new Bundle();
//        args.putInt(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_GROUP);
//        args.putString(EaseConstant.EXTRA_USER_ID, "zhoukang");
        chatFragment.setArguments(getIntent().getExtras());
        getSupportFragmentManager().beginTransaction().add(R.id.ec_layout_container, chatFragment).commit();
        /**
         * 垃圾公司没手机怎么测试
         */
//        DebugNotification.transmission(SendAMessageActivity.this, handler);


    }

    private void initIntent() {
        if (getIntent() != null) {
            doctorname = getIntent().getStringExtra("doctorname");
            com.orhanobut.logger.Logger.e("医生名字" + doctorname);
        }
    }

}
